home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2342 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  64 lines

  1. Path: news.cc.emory.edu!larry!libjrm
  2. From: John Marsh <libjrm@emory.edu>
  3. Newsgroups: comp.lang.c
  4. Subject: HELP! #include <math.c> question
  5. Date: Sat, 20 Jan 1996 14:01:06 -0500
  6. Organization: Emory University
  7. Message-ID: <Pine.SV4.3.91.960120135347.12016A-100000@larry>
  8. NNTP-Posting-Host: larry.cc.emory.edu
  9. Mime-Version: 1.0
  10. Content-Type: TEXT/PLAIN; charset=US-ASCII
  11. X-Sender: libjrm@larry
  12.  
  13. Hi folks-
  14.  
  15. I'm trying to learn C, and have encountered a problem compiling a 
  16. bit of code. I've tried it on two GNU compilers at different locations, 
  17. and gotten the same error message. My code looks like this:
  18. _________________________________________________________________________
  19.  
  20. #include <stdio.h>
  21. #include <math.h>
  22.  
  23. int
  24. main(void)
  25. {
  26.     double first, second,
  27.            first_sqrt,
  28.            second_sqrt,
  29.            sum_sqrt;
  30.  
  31.     printf("Enter the first number> ");
  32.     scanf("%lf",&first);
  33.     first_sqrt = sqrt(first);
  34.     printf("The square root of the first number is %.2f\n", first_sqrt);
  35.  
  36.     printf("Enter the second number> ");
  37.     scanf("%lf",&second);
  38.     second_sqrt = sqrt(second);
  39.     printf("The square root of the second number is %.2f\n", second_sqrt);
  40.  
  41.     sum_sqrt = sqrt(first + second);
  42.     printf("The square root of the sum of the two numbers is %.2f\n",
  43.         sum_sqrt);
  44.  
  45.     return(0);
  46. }
  47. _____________________________________________________________________________
  48.  
  49. When I try to compile it, I get an "Undefined symbol (sqrt) - Symbol 
  50. referencing error" message. Shouldn't <math.h> recognize sqrt? I must be 
  51. missing something, obviously, but I'm at a loss... Any help would be 
  52. greatly appreciated (and if you choose to respond, please .cc me at 
  53. libjrm@emory.edu if you don't mind).
  54.  
  55. Many thanks in advance!
  56.  
  57.                                  John Marsh
  58.                      Reference Dept. - Woodruff Library
  59.                        Emory University - Atlanta, GA
  60.                                (404) 727-6876 
  61.                               libjrm@emory.edu
  62.  
  63.  
  64.